define(['jquery','static','text!../template/examOpen.html','common'],function($,static,tplExamOpen,common){
	let exam={};
	let tpls = {
		'tplExamOpen' :_.template(tplExamOpen)
	};

	exam.show = function(data,page,source){
		Ajax('/xjrest/audit/aduit_detail?opModel='+data.opModel+'&bizNew='+data.bizNew+'&bizOld='+data.bizOld,aduitDetailBack);
		function aduitDetailBack(result){
			if(result.ret.success){
				let _data = result.ret;
				_data.auditTitle = data.auditTitle;
				_data.userName = data.userName;
				_data.submitTime = data.submitTime;
				_data.opModel = data.opModel;
				_data.opType = data.opType;
				_data.showType = data.type;
				_data.auditStatus = data.auditStatus;
				_data.auditRemark = data.auditRemark;
				_data.role = static.currentUser.role;
				_data.examTime = data.auditStatus!=1?data.auditTime:'待审核';
				let _html = tpls.tplExamOpen({message:_data});
				layer.open({
				  type: 1,
				  title: false,
				  closeBtn: 0,
				  shadeClose: true,
				  skin: 'examOpen',
				  content: _html
				});
				if(data.auditStatus!=1){
					$('.exam-check label').css('pointer-events','none');
					$('#examMsg').css('pointer-events','none');
				}
				$('#adopt,#dieOut').change(function(event) {
					$('.typeImg').toggle();
					if($("input[type='radio']:checked").val()==3){
						$('#examMsg').show();
					}else{
						$('#examMsg').hide();
					}
				});
				$('#closeInfo').click(function(event) {
					$('.layui-layer-shade').click();
				});
				$('#exaMapClose').click(function(event) {
					$('.exaMap').hide();
				});
				if(_data.auditStatus==3){
			    	$('#dieOut').click();
			    	$('#examMsg').show();
			    }
				$('#examSubmit').click(function(event) {
					let parms={};
					parms.auditStatus  = $("input[type='radio']:checked").val();
					parms.auditRemark  = $("#examMsg").val();
					if(parms.auditStatus==3&&parms.auditRemark==''){
						layer.msg('请填写未通过原因')
						return;
					}
					parms.opModel = data.opModel;
					parms.auditId  = data.auditId;
					parms.opType  = data.opType;
					parms.bizId  = data.bizId;
					let newPoint = result.ret.value;
					if(data.opModel==1){
						parms.submitUser = data.submitUser;
						parms.username= newPoint.userName;
						parms.gender= newPoint.gender;
						parms.phone= newPoint.phone;
						parms.password= newPoint.password;
						parms.role= newPoint.role;
					}else if (data.opModel==2) {
						parms.pointName  = newPoint.pointName;
						parms.townId  = newPoint.townId;
						parms.villageId  = newPoint.villageId;
						parms.pointAddress  = newPoint.pointAddress;
						parms.buildTime  = newPoint.buildTime;
						parms.manufacturer  = newPoint.manufacturer;
						parms.equipmentNum  = newPoint.equipmentNum;
						parms.useTime  = newPoint.useTime;
						parms.linkman  = newPoint.linkman;
						parms.linkphone  = newPoint.linkphone;
						parms.equipmentType  = newPoint.equipmentType;
						parms.remark  = newPoint.remark;
						parms.longitude  = newPoint.longitude;
						parms.latitude  = newPoint.latitude;
						parms.createUser  = newPoint.createUser;
					}
					Ajax('/xjrest/audit/audit_process',aduitProcessBack,parms);
					function aduitProcessBack(data){
						if(data.ret.success){
							layer.closeAll();
							layer.msg('审核完成');
							if (source == 1) {
								page==1?setHomeExamine(0,100):setExamineTable(0,100,'exIng');
							} else {
								page==1?setHomeExamine(0,5):setExamineTable(0,5,'exIng');
							}
						}
					}
				});
			}
		}
	}

	return exam;
})